<?php

namespace App\V3\V3_1\Controllers;

use App\V3\V3_1\Services\OrderService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

/**
 * 订单管理
 * AUTHOR  : zl
 * DateTime: 2022/08/18
 */
class OrderController extends BaseController
{
    /**
     * 微信支付
    */
    public function WechatPay(Request $request)
    {
        //参数验证
        $validator = Validator::make($data = $request->all(), [
             'type' => [
                'required',
                Rule::In([1, 2]),
            ],//订单类型 1vip充值 2购买空间
            'pay_type' => [
                'required',
                Rule::In([1, 2]),
            ],//支付类型 1小程序 2app
        ],
        [
            'type.required' => '请选择类型',
            'type.in' => '类型不合法，请重新选择',
            'pay_type.required' => '请选择类型',
            'pay_type.in' => '类型不合法，请重新选择',

        ]);

        //参数错误响应
        if ($info = $validator->errors()->first()) {
            return $this->fail('', $info);
        }
        return response()->json(OrderService::createOrder($this->getMainUserId(),$data));
    }
}
